<template>
  <div class="n_HNotice">
    <div class="n_HNotice_title">
      <span class="title">{{ allocationObj.title }}</span>
      <span class="look_all" @click="lookAll">查看全部</span>
    </div>
    <div class="n_HNotice_list" v-if="isHome">
      <ul v-if="listData.length > 0">
        <li @click="lookDetails(item)" v-for="item in listData" :key="item.i">
          <template v-if="allocationObj.selectValue == 'message'">
            <span class="title">
              <!-- <i style="color: #0079dc" class="el-icon-tickets"></i> -->
              <img
                class="root_list"
                src="@/assets/images/root-list.png"
                alt=""
              />
              {{ item.title }}</span
            >
            <span class="time">{{
              item.lastModifyTime | toDate("yyyy-MM-dd")
            }}</span>
          </template>
          <template v-else>
            <span class="title"
              ><img
                class="root_list"
                src="@/assets/images/root-list.png"
                alt=""
              />{{ item.fullName }}</span
            >
            <span class="time">{{
              item.creatorTime | toDate("yyyy-MM-dd")
            }}</span>
          </template>
        </li>
      </ul>
      <div v-else style="text-align: center; margin-top: 20px">
        <img
          src="@/assets/images/portal-nodata.png"
          alt=""
          class="noData-img"
        />
        <p class="noData-txt">暂无数据</p>
      </div>
    </div>
    <Form v-if="formVisible" ref="Form" />
  </div>
</template>
<script>
import { getNotice } from "@/api/home";
import request from "@/utils/request";
import Form from "@/views/basic/messageRecord/Form.vue";
// import { getCrmCustomerVerify } from "@/api/crm/customer";
// import { getMessageList, ReadInfo, MessageAllRead } from "@/api/system/message";
// import Form from '@/views/basic/messageRecord/Form'
export default {
  components: { Form },
  props: {
    allocationObj: { default: "" },
    isHome: { default: true },
  },
  // components: { Form },
  data() {
    return {
      formVisible: false,
      list: [],
      listData: [],
      formVisible: false,
    };
  },
  created() {
    console.log(this.allocationObj, "配置");
    this.getData();
  },
  methods: {
    getData() {
      request({
        url: `${this.allocationObj.port}`,
        method: "get",
        data: {},
      }).then((res) => {
        console.log(res, "这里么！！！！！");
        // this.listData = res.data.list
        if (res.data.list.length > 4) {
          this.listData = res.data.list.slice(0, 5);
        } else {
          this.listData = res.data.list;
        }
      });
    },
    lookDetails(item) {
      console.log(this.allocationObj);
      if (this.allocationObj.selectValue == "message") {
        // readInfo(item) {
        ReadInfo(item.id).then((res) => {
          console.log("消息item...", item, res);
          // 获取审批信息，通过enCode 判断进入哪个页面

          this.info = res.data;
          this.files = res.data.files ? JSON.parse(res.data.files) : [];
          if (item.isRead == "0") {
            item.isRead = "1";
            this.$emit("read");
          }
          if (item.type == 1) {
            // this.visible = true;
            // 公告
            this.formVisible = true;
            // this.list[i].isRead = 1;
            this.$nextTick(() => {
              this.$refs.Form.init(item.id);
            });
          } else {
            let responseData = JSON.parse(res.data.bodyText);
            let verifyId = JSON.parse(res.data.bodyText).id;
            if (!res.data.bodyText) return;
            if (item.type == 1) {
              console.log("跳转类型四", res);
              // this.$router.push({
              //   path: "/crm/crmworkitem",
              //   query: {
              //     id: JSON.parse(item.bodyText).id,
              //   },
              // });
              // this.drawer = false;
            }
            if (item.type == 4) {
              // console.log("跳转类型四", res);
              this.$router.push({
                path: "/crm/crmworkitem",
                query: {
                  id: JSON.parse(item.bodyText).id,
                },
              });
              this.drawer = false;
            }
            // var obj = JSON.parse(res.data);

            if (item.type == 3) {
              this.$router.push({
                path: "/crm/crmcustomeropportunity",
                query: {
                  id: JSON.parse(item.bodyText).id,
                },
              });
              this.drawer = false;
            } else if (item.type == 2) {
              if (!res.data.bodyText) return;
              let _userInfo = this.$store.getters.userInfo;
              console.log(
                "_userINfo...",
                _userInfo,
                JSON.parse(res.data.bodyText)
              );

              this.drawer = false;
              const Base64 = require("js-base64").Base64;
              //查询客户信息的审核状态,判断enCode进行跳转
              if (responseData.enCode == "RkContractVerify") {
                // 如果合同是给发起人发送的消息
                if (responseData.status == "3") {
                  this.$router.push({
                    path: "/contract/contract/approval",
                    query: {
                      ...res.data,
                      ischeck: true,
                    },
                  });
                } else {
                  // 如果合同是给审批人发送的消息
                  this.$router.push({
                    path: "/workFlow/flowTodo",
                    query: {
                      ...res.data,
                      ischeck: true,
                    },
                  });
                }
              } else if (responseData.enCode == "CrmCustomerVerify") {
                // console.log("JSON.parse(item.bodyText)", item);
                if (!isEmpty(JSON.parse(item.bodyText))) {
                  console.log(
                    "JSON.parse(item.bodyText)",
                    JSON.parse(item.bodyText)
                  );
                  let data = this.getFirstPropertyValue(
                    JSON.parse(item.bodyText)
                  );

                  if (!isEmpty(JSON.parse(data))) {
                    getCrmCustomerVerify(JSON.parse(data).processId).then(
                      (rr) => {
                        if (rr.data.enabledMark == 2) {
                          //通过
                          this.$router.push({
                            path: "/crm/crmcustomer",
                            query: {
                              ...rr.data,
                            },
                          });
                        } else if (rr.data.enabledMark == 5) {
                          //拒绝
                          if (_userInfo.isAdministrator) {
                            //管理员
                            this.$router.push({
                              path: "/workFlow/flowDone",
                              query: {
                                ...res.data,
                              },
                            });
                          } else {
                            this.$router.push({
                              path: "/crm/crmcustomerverify",
                              query: {
                                ...rr.data,
                              },
                            });
                          }
                        } else if (rr.data.enabledMark == 3) {
                          //撤回
                          this.$message({
                            message: "用户已撤回！",
                            type: "warning",
                            duration: 1500,
                            onClose: () => {},
                          });
                        } else {
                          this.$router.push({
                            path: "/workFlow/flowTodo",
                            query: {
                              ...res.data,
                            },
                          });
                        }
                      }
                    );
                  }
                } else {
                  return;
                }
              } else {
                // 如果合同是给审批人发送的消息
                // let codeData = Base64.enCode(...res.data);
                // console.log(JSON.parse(item.bodyText), "------<<<<<<");
                // getCrmCustomerVerify(JSON.parse(item.bodyText).id).then((rr) => {
                //   console.log(rr, "------>>>>");
                // });
                if (JSON.parse(res.data.bodyText).type == 1) {
                  this.$router.push({
                    path: "/workFlow/flowLaunch",
                    query: {
                      ...res.data,
                      ischeck: true,
                      taskOperatorId: JSON.parse(res.data.bodyText)
                        .taskOperatorId,
                      timestamp: new Date().getTime(),
                    },
                  });
                } else if (JSON.parse(res.data.bodyText).type == 2) {
                  this.$router.push({
                    path: "/workFlow/flowTodo",
                    query: {
                      ...res.data,
                      ischeck: true,
                      taskOperatorId: JSON.parse(res.data.bodyText)
                        .taskOperatorId,
                      timestamp: new Date().getTime(),
                    },
                  });
                } else if (JSON.parse(res.data.bodyText).type == 3) {
                  this.$router.push({
                    path: "/workFlow/flowCirculate",
                    query: {
                      ...res.data,
                      ischeck: true,
                      taskOperatorId: JSON.parse(res.data.bodyText)
                        .taskOperatorId,
                      timestamp: new Date().getTime(),
                    },
                  });
                }
              }

              // }
            } else if (item.type == 10) {
              // 审核通过及驳回，跳转到新增客户列表页
              if (!res.data.bodyText) return;
              this.drawer = false;
              // const Base64 = require("js-base64").Base64;
              this.$router.push({
                path: "/crm/crmcustomerverify",
                query: {
                  id: verifyId,
                },
              });
            } else if (item.type == 20) {
              this.drawer = false;
              //合同列表
              this.$router.push({
                path: "/contract/contract/input",
              });
            } else if (item.type == 21) {
              this.drawer = false;
              //合同列表
              this.$router.push({
                path: "/contract/returnPlan",
              });
            } else if (item.type == 40) {
              //售前消息列表
              let data = JSON.parse(item.bodyText);
              this.$router.push({
                path: "/before-sale/before-sale-support/index.vue",
                query: {
                  id: data.id,
                },
              });
            } else if (item.type == 50) {
              //拜访
              this.drawer = false;
              console.log("拜访----", item);
              let data = JSON.parse(item.bodyText);
              let id = data.AppUrl.split("id=")[1];
              //请求数据,根据type值跳转页面
              let type = "";
              request({
                url: "/api/visit/VisitFollowUp/" + id,
                method: "get",
              }).then((itemType) => {
                type = itemType.data.visitType;
                if (type == "sale") {
                  this.$router.push({
                    // path: "/before-sale/before-sale-bid/index.vue",
                    path: "/visit/follow-up/index-sale",
                    query: {
                      id: id,
                      creatorUserName: item.creatorUser,
                      ischeck: true,
                    },
                  });
                }
                if (type == "beforeSale") {
                  this.$router.push({
                    // path: "/before-sale/before-sale-bid/index.vue",
                    path: "/visit/follow-up/before-sale",
                    query: {
                      id: id,
                      creatorUserName: item.creatorUser,
                      ischeck: true,
                    },
                  });
                }
                if (type == "afterSale") {
                  this.$router.push({
                    // path: "/before-sale/before-sale-bid/index.vue",
                    path: "/visit/follow-up/after-sale",
                    query: {
                      id: id,
                      creatorUserName: item.creatorUser,
                      ischeck: true,
                    },
                  });
                }
              });
            } else if (item.type == 60) {
              //会议消息列表
              let data = JSON.parse(item.bodyText);
              if (data.type == "verify") {
                this.$router.push({
                  path: "/meeting/meeting-approve",
                  query: {
                    id: data.id,
                  },
                });
              } else if (data.type == "viewCreate") {
                this.$router.push({
                  path: "/meeting/meeting-myself",
                  query: {
                    id: data.id,
                  },
                });
              } else if (data.type == "viewParticipate") {
                this.$router.push({
                  path: "/meeting/meeting-participate/index.vue",
                  query: {
                    id: data.id,
                  },
                });
              } else if (data.type == "uploadMinutes") {
                this.$router.push({
                  path: "/meeting/meeting-participate/index.vue",
                });
              }
            } else if (item.type == 70) {
              //会议跟踪重要事项消息列表
              let data = JSON.parse(item.bodyText);
              console.log("会议跟踪", data);
              this.$router.push({
                path: "/meeting/important-work/department-plan/index.vue",
                //meeting/important-work/department-plan/index.vue
                query: {
                  id: data.id,
                  jump: (Math.random() * 10000).toFixed(0),
                },
              });
            } else if (item.type == 80) {
              //拜访
              let data = JSON.parse(item.bodyText);
              this.$router.push({
                path: "/before-sale/before-sale-bid/index.vue",
                query: {
                  id: data.id,
                },
              });
            } else if (item.type == 30) {
              //商机统计
              this.$router.push({
                path: "/model/shangjitotal",
              });
            } else if (item.type == 31) {
              // 7天未根据商机动态提醒
              this.$router.push({
                path: "/crm/crmcustomeropportunity",
              });
            } else if (item.type == 34) {
              // 问题列表
              this.$router.push({
                path: "/after-sales/question",
              });
            } else if (item.type == 35) {
              // 问题列表
              this.$router.push({
                path: "/after-sales/question",
              });
            } else if (item.type == 36) {
              // 巡检任务
              this.$router.push({
                path: "/after-sales/inspect/task",
              });
            } else if (item.type == 37) {
              // 巡检任务 撤回
              this.$router.push({
                path: "/after-sales/inspect/task",
              });
            } else if (item.type == 33) {
              //销售在移动端提交客户
              this.$message({
                message: "请在移动端查看",
                type: "warning",
                duration: 1500,
              });
            } else if (item.type == 63) {
              this.drawer = false;
              this.$router.push({
                path: "/before-sale/before-sale-support-list/index.vue",
              });
            } else if (item.type == 81 || item.type == 82) {
              //线索
              let data = JSON.parse(item.bodyText);
              this.$router.push({
                path: "/crm/clue/index.vue",
                query: {
                  id: data.businessId,
                },
              });
            }
            // console.log(encodeURIComponent(Base64.encode(res.data.bodyText)));
            // this.drawer = false
            // const Base64 = require('js-base64').Base64
            // this.$router.push('/workFlowDetail?config=' + encodeURIComponent(Base64.encode(res.data.bodyText)))
          }
        });
      } else if (this.allocationObj.selectValue == "flowTodo") {
        let config = JSON.stringify(item);
        const Base64 = require("js-base64").Base64;
        this.$router.push(
          "/workFlowDetail?config=" + encodeURIComponent(Base64.encode(config))
        );
      } else {
        // 公告
        this.formVisible = true;
        // this.list[i].isRead = 1;
        this.$nextTick(() => {
          this.$refs.Form.init(item.id);
        });
      }

      // }
    },
    lookAll() {
      console.log(this.allocationObj, "---");
      if (this.allocationObj.selectValue == "email") {
        this.$router.push("/extend/email");
      } else if (this.allocationObj.selectValue == "announcement") {
        this.$router.push({
          path: "/messageRecord?type=" + 1,
        });
      }
    },
    getFirstPropertyValue(obj) {
      for (let prop in obj) {
        return obj[prop];
      }
    },

    // readInfo(id) {
    //   this.formVisible = true
    //   this.$nextTick(() => {
    //     this.$refs.Form.init(id)
    //   })
    // }
  },
};
</script>
<style lang="scss" scoped>
.n_HNotice {
  background-color: #fff;
  padding: 15px;
  height: 100%;
  border-radius: 8px;
  .title {
    font-family: "PingFang SC";
    font-weight: 400;
    font-size: 16px;
    color: #000000;
    line-height: 24px;
    padding: 0 10px;
  }
  .look_all {
    font-family: "PingFang SC";
    font-weight: 400;
    font-size: 14px;
    color: #acadad;
    line-height: 27px;
    float: right;
    cursor: pointer;
  }
  .look_all:hover {
    color: #008dff;
  }
}
.n_HNotice_list {
  margin-top: 10px;
  i {
    color: #008dff;
    opacity: 0.2;
    position: relative;
    top: 11px;
    float: left;
  }
  .title {
    // display: inline-block;
    width: calc(100% - 110px);
    padding: 0 3px;
    font-family: "PingFang SC";
    font-weight: 400;
    font-size: 14px;
    color: #000000;
    line-height: 36px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    float: left;
    cursor: pointer;
  }
  .title:hover {
    color: #008dff;
  }
  .time {
    font-family: "PingFang SC";
    font-weight: 400;
    font-size: 14px;
    color: #acadad;
    line-height: 36px;
    float: right;
    // float: left;
  }
  .noData-img {
    text-align: center;
    margin: auto;
    width: 100px;
  }
  .noData-txt {
    text-align: center;
    color: #999;
  }
}
.el-icon-tickets {
  position: relative;
  top: 4px;
  display: inline-block;
  margin-right: 3px;
  color: #0079dc;
}
.root_list {
  position: relative;
  top: 4px;
  margin-right: 3px;
}
li {
  list-style-type: none;
  height: 36px;
}
</style>
